package com.ziyun.erp.web.modules.logistics.controller;

import com.ziyun.erp.modules.logistics.entity.ErpLogisticsItemEntity;
import com.ziyun.erp.modules.logistics.service.ErpLogisticsItemService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 订单配送明细表
 *
 * @author guizhao
 * @email ...
 * @date 2018-08-31 10:12:35
 */
@RestController
@RequestMapping("logistics/erplogisticsitem")
public class ErpLogisticsItemController {
    @Autowired
    private ErpLogisticsItemService erpLogisticsItemService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("logistics:erplogisticsitem:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = erpLogisticsItemService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{logiItemId}")
    @RequiresPermissions("logistics:erplogisticsitem:info")
    public R info(@PathVariable("logiItemId") Integer logiItemId){
        ErpLogisticsItemEntity erpLogisticsItem = erpLogisticsItemService.selectById(logiItemId);

        return R.ok().put("erpLogisticsItem", erpLogisticsItem);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("logistics:erplogisticsitem:save")
    public R save(@RequestBody ErpLogisticsItemEntity erpLogisticsItem){
        erpLogisticsItemService.insert(erpLogisticsItem);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("logistics:erplogisticsitem:update")
    public R update(@RequestBody ErpLogisticsItemEntity erpLogisticsItem){
        ValidatorUtils.validateEntity(erpLogisticsItem);
        erpLogisticsItemService.updateAllColumnById(erpLogisticsItem);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("logistics:erplogisticsitem:delete")
    public R delete(@RequestBody Integer[] logiItemIds){
        erpLogisticsItemService.deleteBatchIds(Arrays.asList(logiItemIds));

        return R.ok();
    }

}
